package com.lm.activiti.boot.mq.rabbit;

import com.lm.activiti.boot.mq.common.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author lm_jcf
 * @date 2020/8/31 16:15
 */
public class Producer {

    private static final String queueName = "multi_producer_1";


    /**
     *
     * 交换机类型：exchange type = topic 主题模式
     * 通过通配符匹配与之绑定的队列
     * 将 routing key 和某个模式匹配，
     * # 匹配一个或多个、* 匹配一个
     */
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        Connection connection = ConnectionUtils.getConnection();

        String queueName = "test_exchange_topic_queue";
//        String exchangeName = "test_exchange_topic";

        // 从链接中获取一个通道
        Channel channel = connection.createChannel();

        // 创建队列声明
        channel.queueDeclare(queueName, false, false, false, null);


        for (int i = 0; i < 20; i++) {
            channel.basicPublish("", queueName, null, "multi_producer_1".getBytes());

            System.out.println("success " + i);
            Thread.sleep(4000);
        }

        channel.close();
        connection.close();
    }


}
